package game.module.item.dao;

import game.module.item.beans.CharacterGoods;

import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class GoodsDataEntryManager {

	public static final Logger logger = LoggerFactory.getLogger(GoodModelCache.class);

	@Autowired
	private GoodsDao goodsDao;

	@Async
	public void updataCharacterGoods(CharacterGoods goods) {
		try {
			goodsDao.updateAll(goods);
		} catch (SQLException e) {
			logger.error("", e);
		}
	}

	public void scheduleExecute() {
		logger.info("schedule deleteCharacterGoods!");
	}

	public void cronSchedule() {
		logger.info("cron schedule");
	}

	@Async
	public void deleteCharacterGoods(int goodsId) {
		try {
			goodsDao.deleteById(goodsId);
		} catch (SQLException e) {
			logger.error("", e);
		}
	}

	@Async
	public void updateGoodsPositonCount(CharacterGoods goods) {
		try {
			goodsDao.updatePositionAndCount(goods.getPosition(), goods.getCount(), goods.getId());
		} catch (SQLException e) {
			logger.error("", e);
		}
	}

	@Async
	public void insertCharacterGoods(CharacterGoods record) {
		try {
			goodsDao.insert(record);
		} catch (SQLException e) {
			logger.error("", e);
		}
	}

}
